package cn.chen.server.ctrl;

import cn.chen.server.listener.NettyServerListener;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import cn.chen.server.util.SendMsg;

import javax.annotation.Resource;

//向客户端发送指令
@RestController
public class SendCtrl {
	@Resource
	private NettyServerListener nettyServerListener;

	@GetMapping("send")
	public String send(@RequestParam("port") String port, @RequestParam("msg") String msg) {
		return SendMsg.sendMsg(port, msg) ? "发送成功" : "设备不在线";
	}

	@GetMapping("netty/start")
	public String nettyStart() {
		try {
			nettyServerListener.start();
			return "netty启动成功";
		} catch (Exception e) {
			return "netty已经正常启动，请不要重复启动！";
		}
	}
}
